/* Copyright 2012 Dustin Mitchell <dmmitche [at] gmail [dot] com>
 *
 * Licensed under the GPLv3.  See included LICENSE.txt for full details.
 */

#ifndef __SYNC_QUEUE__
#define __SYNC_QUEUE__

#include <sys/types.h>
#include <pthread.h>

#include "list.h"

struct sync_queue
{
  size_t n_queued;
  struct list queue;
  pthread_mutex_t sync;
  pthread_cond_t cond;
};

int sync_queue_create (struct sync_queue *queue);

void sync_queue_destroy (struct sync_queue *queue);

int sync_queue_insert (struct sync_queue *queue, void *data);

/* Blocks waiting for an item on the queue to remove */
void * sync_queue_remove (struct sync_queue *queue);

/* Removes and item if available, updates status with whether an item was
 * available */
void * sync_queue_tryremove (struct sync_queue *queue, int *status);

#endif /* __SYNC_QUEUE__ */
